local qinxue = fk.CreateSkill {

  name = "joyex__qinxue",

  tags = { Skill.Wake, },

}



qinxue:addEffect(fk.EventPhaseStart, {
  name = "joyex__qinxue",
  frequency = Skill.Wake,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(qinxue.name) and
      player.phase == Player.Finish and
      player:usedSkillTimes(qinxue.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return #player.player_cards[Player.Hand] >= player.hp*3
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:isWounded() then
      local n = player.maxHp - player.hp
      room:changeMaxHp(player, -n)
    end
    room:handleAddLoseSkills(player, "-joy__keji", nil)
    room:handleAddLoseSkills(player, "joy__gongxin", nil)
  end,
})

return qinxue